package com.huawei.statistics.platform.init;

import com.huawei.statistics.schedule.job.MyQuartzJobBean;
import com.huawei.statistics.service.schedule.quartz.ScheduleService;
import com.huawei.statistics.utils.DateTimeUtilT;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * Created by Administrator on 2018/7/4/004.
 */
@Component
public class SystemStartListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    ScheduleService scheduleService;


    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {

        String firstDay = "";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        //获取下个月的第一天
//        Calendar   cal_1= Calendar.getInstance();//获取当前日期
//        cal_1.add(Calendar.MONTH, +1);
//        cal_1.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
//        firstDay = format.format(cal_1.getTime());
//        String str = firstDay + " 00:00:01";
//        System.out.println(str+"启动了一个定时器");
//        scheduleService.scheduleEvenIfDateAfterNow("setMemberGroup", DateTimeUtilT.dateTime(str), MyQuartzJobBean.SET_MEMBERGROUP);
        Calendar cal1 = Calendar.getInstance();
        cal1.add(Calendar.DAY_OF_MONTH,+1);
        cal1.set(Calendar.HOUR_OF_DAY,4);
        cal1.set(Calendar.MINUTE,0);
        cal1.set(Calendar.SECOND,0);
        System.out.println(DateTimeUtilT.dateTime(cal1.getTime())+"开启了一个定时器");
        scheduleService.scheduleEvenIfDateAfterNow("getAIQIYIVIDEO", cal1.getTime(), MyQuartzJobBean.GET_AQIYIVIDEO);

    }
}
